### MANAGED BY {{ role_path|basename }} ANSIBLE ROLE ###

[global_tags]
{% if telegraf_global_tags is defined and telegraf_global_tags is iterable %}
{% for item in telegraf_global_tags %}
    {{ item.tag_name }} = "{{ item.tag_value }}"
{% endfor %}
{% endif %}
{% if onecloud_vm_id is defined %}
    vm_id = "{{ onecloud_vm_id }}"
{% endif %}
{% if onecloud_tenant_id is defined %}
    tenant_id = "{{ onecloud_tenant_id }}"
{% endif %}
{% if onecloud_domain_id is defined %}
    domain_id = "{{ onecloud_domain_id }}"
{% endif %}

{% if telegraf_agent_aws_tags == true and ec2_tags is defined and ec2_tags != None %}
{% for key, value in ec2_tags.tags.items()%}
   {{telegraf_agent_aws_tags_prefix}}{{ key }} = "{{ value }}"
{% endfor %}
{% endif %}

# Configuration for telegraf agent
[agent]
    interval = "{{ telegraf_agent_interval }}s"
    debug = {{ telegraf_agent_debug | lower }}
    hostname = "{{ telegraf_agent_hostname }}"
    round_interval = {{ telegraf_agent_round_interval | lower }}
    flush_interval = "{{ telegraf_agent_flush_interval }}s"
    flush_jitter = "{{ telegraf_agent_flush_jitter }}s"
{% if telegraf_agent_version is version_compare('0.13', '>=') %}
    collection_jitter = "{{ telegraf_agent_collection_jitter }}s"
    metric_batch_size = {{ telegraf_agent_metric_batch_size }}
    metric_buffer_limit = {{ telegraf_agent_metric_buffer_limit }}
    quiet = {{ telegraf_agent_quiet | lower }}
{% endif %}
{% if telegraf_agent_version is version_compare('1.1', '>=') %}
{% if ansible_os_family == "Windows" %}
    logfile = "{{ telegraf_win_logfile }}"
{% else %}
    logfile = "{{ telegraf_agent_logfile }}"
{% endif %}
    omit_hostname = {{ telegraf_agent_omit_hostname | lower }}
{% endif %}

###############################################################################
#                                  OUTPUTS                                    #
###############################################################################

{% if telegraf_agent_output is defined and telegraf_agent_output is iterable %}
{% for item in telegraf_agent_output %}
[[outputs.{{ item.type }}]]
{% for items in item.config %}
    {{ items }}
{% endfor %}
{% if item.tagpass is defined and item.tagpass is iterable %}
[outputs.{{ item.type }}.tagpass]
{% for items in item.tagpass %}
    {{ items }}
{% endfor %}
{% endif %}
{% if item.tagdrop is defined and item.tagdrop is iterable %}
[outputs.{{ item.type }}.tagdrop]
{% for items in item.tagdrop %}
    {{ items }}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}

###############################################################################
#                                  INPUTS                                     #
###############################################################################

{% if telegraf_plugins_default is defined and telegraf_plugins_default is iterable %}
{% for item in telegraf_plugins_default %}
[[inputs.{{ item.plugin }}]]
{% if item.interval is defined %}
    interval = "{{ item.interval }}s"
{% endif %}
{% if item.config is defined and item.config is iterable %}
{% for items in item.config %}
    {{ items }}
{% endfor %}
{% endif %}
{% if item.tags is defined and item.tags is iterable %}
[inputs.{{ item.plugin }}.tags]
{% for items in item.tags %}
    {{ items }}
{% endfor %}
{% endif %}
{% if item.tagpass is defined and item.tagpass is iterable %}
[inputs.{{ item.plugin }}.tagpass]
{% for items in item.tagpass %}
    {{ items }}
{% endfor %}
{% endif %}
{% if item.tagdrop is defined and item.tagdrop is iterable %}
[inputs.{{ item.plugin }}.tagdrop]
{% for items in item.tagdrop %}
    {{ items }}
{% endfor %}
{% endif %}
{% if item.objects is defined and item.objects is iterable %}
{% for object in item.objects %}
[[inputs.{{ item.plugin }}.object]]
  ObjectName = {{ object.name | to_json }}
  Instances = {{ object.instances | default(["*"]) | to_json }}
  Counters = {{ object.counters | default(["*"]) | to_json }}
  Measurement = {{ object.measurement | default("win_perf_counters") | to_json }}
  IncludeTotal = {{ object.total | default(false) | string | lower }}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}

{% if telegraf_plugins_default is defined and telegraf_plugins_default|length == 0 %}
{% if telegraf_plugins_extra is defined and telegraf_plugins_extra.keys() | length == 0 %}
# No plugins configured, added a mem plugin so telegraf doesn't stop working.
[[inputs.mem]]
{% endif %}
{% endif %}

###############################################################################
#                                  PROCESSORS                                    #
###############################################################################

{% if telegraf_processors is defined and telegraf_processors is iterable %}
{% for item in telegraf_processors %}
[[processors.{{ item.processor }}]]
{% if item.config is defined and item.config is iterable %}
{% for items in item.config %}
    {{ items }}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
